<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author LYS
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'cardd:rwjjmx:carddRwjjmx:edit'">
          <Icon icon="i-fluent:add-12-filled" />
          {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ id: record.id })">
          {{ record.rwjjmxJsymc }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="ViewsCarddRwjjmxCarddRwjjmxList">
  import { unref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicColumn, BasicTable, useTable } from '/@/components/Table';
  import { carddRwjjmxDelete, carddRwjjmxListData } from '/@/api/cardd/rwjjmx/carddRwjjmx';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('cardd.rwjjmx.carddRwjjmx');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('任务奖金明细管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('日期'),
        field: 'rwjjmxRq',
        component: 'DatePicker',
        componentProps: {
          picker: 'month',
          format: 'YYYY-MM',
          valueFormat: 'YYYY-MM',
        },
      },
      {
        label: t('驾驶员名称'),
        field: 'rwjjmxJsymc',
        component: 'Input',
      },
      {
        label: t('车牌号'),
        field: 'rwjjmxCph',
        component: 'Input',
      },
      {
        label: t('用车单位'),
        field: 'rwjjmxYcdwmc',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('日期'),
      dataIndex: 'rwjjmxRq',
      key: 'a.rwjjmx_rq',
      sorter: true,
      width: 70,
      align: 'left',
    },
    {
      title: t('上车日期'),
      dataIndex: 'rwjjmxKsrq',
      key: 'a.rwjjmx_ksrq',
      sorter: true,
      width: 145,
      align: 'left',
    },
    {
      title: t('车单编号'),
      dataIndex: 'rw.ycddrwCdbh',
      key: 'rw.ycddrw_cdbh',
      sorter: true,
      width: 90,
      align: 'left',
    },
    {
      title: t('驾驶员'),
      dataIndex: 'rwjjmxJsymc',
      key: 'a.rwjjmx_jsymc',
      sorter: true,
      width: 80,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('车牌号'),
      dataIndex: 'rwjjmxCph',
      key: 'a.rwjjmx_cph',
      sorter: true,
      width: 90,
      align: 'left',
    },
    {
      title: t('用车单位'),
      dataIndex: 'rwjjmxYcdwmc',
      key: 'a.rwjjmx_ycdwmc',
      sorter: true,
      width: 90,
      align: 'left',
    },
    {
      title: t('小单单价'),
      dataIndex: 'rwjjmxXddj',
      key: 'a.rwjjmx_xddj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('小单数量'),
      dataIndex: 'rwjjmxXdsl',
      key: 'a.rwjjmx_xdsl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('小单小计'),
      dataIndex: 'rwjjmxXdxj',
      key: 'a.rwjjmx_xdxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('半天单价'),
      dataIndex: 'rwjjmxBtdj',
      key: 'a.rwjjmx_btdj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('半天数量'),
      dataIndex: 'rwjjmxBtsl',
      key: 'a.rwjjmx_btsl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('半天小计'),
      dataIndex: 'rwjjmxBtxj',
      key: 'a.rwjjmx_btxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('全天单价'),
      dataIndex: 'rwjjmxQtdj',
      key: 'a.rwjjmx_qtdj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('全天数量'),
      dataIndex: 'rwjjmxQtsl',
      key: 'a.rwjjmx_qtsl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('全天小计'),
      dataIndex: 'rwjjmxQtxj',
      key: 'a.rwjjmx_qtxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超时单价'),
      dataIndex: 'rwjjmxCsdj',
      key: 'a.rwjjmx_csdj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超时数量'),
      dataIndex: 'rwjjmxCssl',
      key: 'a.rwjjmx_cssl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超时小计'),
      dataIndex: 'rwjjmxCsxj',
      key: 'a.rwjjmx_csxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超公里单价'),
      dataIndex: 'rwjjmxCgldj',
      key: 'a.rwjjmx_cgldj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超公里数量'),
      dataIndex: 'rwjjmxCglsl',
      key: 'a.rwjjmx_cglsl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('超公里小计'),
      dataIndex: 'rwjjmxCglxj',
      key: 'a.rwjjmx_cglxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('点单单价'),
      dataIndex: 'rwjjmxDddj',
      key: 'a.rwjjmx_dddj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('点单数量'),
      dataIndex: 'rwjjmxDdsl',
      key: 'a.rwjjmx_ddsl',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('点单小计'),
      dataIndex: 'rwjjmxDdxj',
      key: 'a.rwjjmx_ddxj',
      sorter: true,
      width: 90,
      align: 'right',
    },
    {
      title: t('停车费'),
      dataIndex: 'rwjjmxTcf',
      key: 'a.rwjjmx_tcf',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('洗车费'),
      dataIndex: 'rwjjmxXcf',
      key: 'a.rwjjmx_xcf',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('餐费'),
      dataIndex: 'rwjjmxCf',
      key: 'a.rwjjmx_cf',
      sorter: true,
      width: 70,
      align: 'right',
    },
    {
      title: t('充电费'),
      dataIndex: 'rwjjmxCdf',
      key: 'a.rwjjmx_cdf',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('其他'),
      dataIndex: 'rwjjmxQt',
      key: 'a.rwjjmx_qt',
      sorter: true,
      width: 70,
      align: 'right',
    },
    {
      title: t('合计'),
      dataIndex: 'rwjjmxHj',
      key: 'a.rwjjmx_hj',
      sorter: true,
      width: 70,
      align: 'right',
    },
    {
      title: t('状态'),
      dataIndex: 'status',
      key: 'a.status',
      sorter: true,
      width: 70,
      align: 'center',
      dictType: 'sys_search_status',
    },
    {
      title: t('更新时间'),
      dataIndex: 'updateDate',
      key: 'a.update_date',
      sorter: true,
      width: 110,
      align: 'center',
    },
    {
      title: t('备注'),
      dataIndex: 'remarks',
      key: 'a.remarks',
      sorter: true,
      width: 120,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'i-clarity:note-edit-line',
        title: t('编辑任务奖金明细'),
        onClick: handleForm.bind(this, { id: record.id }),
        auth: 'cardd:rwjjmx:carddRwjjmx:edit',
      },
      {
        icon: 'i-ant-design:delete-outlined',
        color: 'error',
        title: t('删除任务奖金明细'),
        popConfirm: {
          title: t('是否确认删除任务奖金明细'),
          confirm: handleDelete.bind(this, record),
        },
        auth: 'cardd:rwjjmx:carddRwjjmx:edit',
      },
    ],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    api: carddRwjjmxListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const params = { id: record.id };
    const res = await carddRwjjmxDelete(params);
    showMessage(res.message);
    handleSuccess(record);
  }

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
